package fitnesshub.mapper;

import com.github.pagehelper.Page;
import fitnesshub.pojo.dto.ConsumptionRecordPageQueryDTO;
import fitnesshub.pojo.entity.ConsumptionRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ConsumptionRecordMapper {
    /**
     * 消费记录分页
     * @param consumptionRecordPageQueryDTO
     * @return
     */
    Page<ConsumptionRecord> pageQuery(ConsumptionRecordPageQueryDTO consumptionRecordPageQueryDTO);

    /**
     * 插入一条记录
     * @param consumptionRecord
     */
    @Insert("insert into consumption_record (member_id, consumption_type, amount, consumption_date, related_id)" +
            "VALUES " +
            "(#{memberId}, #{consumptionType}, #{amount}, #{consumptionDate}, #{relatedId})")
    void insert(ConsumptionRecord consumptionRecord);

    /**
     * 根据用户id查消费记录
     *
     * @param memberId
     * @return
     */
    @Select("select * from consumption_record where member_id = #{memberId}")
    List<ConsumptionRecord> getByMemberId(Integer memberId);
}
